What is @types/humanize-duration?
@types/humanize-duration provides TypeScript type definitions for the humanize-duration library, which is used to convert durations, given in milliseconds, into human-readable strings.
What are @types/humanize-duration's main functionalities?
Basic Usage
Converts a duration in milliseconds to a human-readable string.
const humanizeDuration = require('humanize-duration');
const humanized = humanizeDuration(3000); // '3 seconds'
Custom Units
Allows customization of the units used in the output string.
const humanizeDuration = require('humanize-duration');
const humanized = humanizeDuration(3000, { units: ['h', 'm', 's'] }); // '3 seconds'
Language Support
Supports multiple languages for the output string.
const humanizeDuration = require('humanize-duration');
const humanized = humanizeDuration(3000, { language: 'es' }); // '3 segundos'
Round
Rounds the output to the nearest integer.
const humanizeDuration = require('humanize-duration');
const humanized = humanizeDuration(3000, { round: true }); // '3 seconds'
Largest
Limits the number of units in the output string.
const humanizeDuration = require('humanize-duration');
const humanized = humanizeDuration(3000, { largest: 1 }); // '3 seconds'
Other packages similar to @types/humanize-duration
moment
Moment.js is a widely-used library for parsing, validating, manipulating, and formatting dates. It includes duration formatting capabilities similar to humanize-duration but offers a broader range of date and time manipulation features.
date-fns
date-fns is a modern JavaScript date utility library that provides a variety of functions for working with dates, including formatting durations. It is modular and tree-shakeable, making it a lightweight alternative to Moment.js.
luxon
Luxon is a library for working with dates and times in JavaScript. It is a modern alternative to Moment.js and includes features for formatting durations, along with extensive support for time zones and internationalization.
Installation
npm install --save @types/humanize-duration
Summary
This package contains type definitions for humanize-duration (https://github.com/EvanHahn/HumanizeDuration.js).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/humanize-duration.
Additional Details
- Last updated: Thu, 04 Jan 2024 00:24:11 GMT
- Dependencies: none
Credits
These definitions were written by Piotr Błażejewicz, and Evan Hahn.